package com.swcw.platform.wlwLog.service.impl;

import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.swcw.platform.constants.Utils;
import com.swcw.platform.external.bean.OwnUsers;
import com.swcw.platform.external.constants.Pagination;
import com.swcw.platform.wlwLog.bean.WlwLog;
import com.swcw.platform.wlwLog.dao.WlwLogMapper;
import com.swcw.platform.wlwLog.service.IWlwLogService;

/**
 * 物联网客户经理问题
 * @see: 
 * @Company:江苏鸿信系统集成有限公司微信开发组 
 * @author 郑建超
 * @Time 2017年3月10日
 * @version 1.0v
 */
@Service("wlwLogService")
public class WlwLogService implements IWlwLogService {

	@Autowired
	private WlwLogMapper wlwLogMapper;// 问题
	
	/**
	 * 
	 * @author 郑建超
	 * @Time 2017年3月10日
	 * @param id
	 * @return
	 */
	@Override
	public WlwLog selectFindById(String id) {
		return wlwLogMapper.selectByPrimaryKey(id);
	}


	/**
	 * @author 郑建超
	 * @Time 2016年12月21日
	 * @param wlwLog
	 * @return
	 */
	@Transactional
	public int add(WlwLog wlwLog) {
		wlwLog.setDateTime(new Date());
		if(StringUtils.isBlank(wlwLog.getId())){
			wlwLog.setId(Utils.getUUID());
		}
		return wlwLogMapper.insertSelective(wlwLog);
	}

	/**
	 * @author 郑建超
	 * @Time 2016年12月21日
	 * @param wlwLog
	 * @return
	 */
	@Transactional
	public int update(WlwLog wlwLog) {
		return wlwLogMapper.updateByPrimaryKeySelective(wlwLog);
	}

	/**
	 * 
	 * @author 郑建超
	 * @Time 2017年3月10日
	 * @return
	 */
	@Override
	public Pagination selectFindByProblems(Pagination pagination) {
		pagination.setTotalCount(wlwLogMapper.selectByWlwLogCount(pagination.getParaMap()));
		pagination.setList(wlwLogMapper.selectByWlwLogMap(pagination.getParaMap()));
		return pagination;
	}

	/**
	 * @author 郑建超
	 * @Time 2017年5月5日
	 * @return
	 */
	@Transactional
	public int addLogs(OwnUsers user, String logs, String logType,String ip) {
		WlwLog wlwLog = new WlwLog();
		wlwLog.setId(Utils.getUUID());
		wlwLog.setUserName(user.getUserName());
		wlwLog.setUserId(user.getId());
		wlwLog.setLogs(logs);
		wlwLog.setLogType(logType);
		wlwLog.setLogIp(ip);
		wlwLog.setDateTime(new Date());
		return wlwLogMapper.insertSelective(wlwLog);
	}
}
